import { getSessionList } from '@/api/msg_session'
import store from '..'

// store.js
export default {
  namespaced: true,

  // 定义state
  state: {
    msgSessionList: null
  },

  // 定义mutations
  mutations: {
    setMsgSessionList (state, obj) {
      // 使用正确的state属性名
      state.msgSessionList = JSON.stringify(obj)
    }
  },
  getters: {
    msgSessionList (state) {
      return state.msgSessionList ? JSON.parse(state.msgSessionList) : null
    }
  },
  actions: {
    async getMsgSessionList (context) {
      const res = await getSessionList(store.getters.userId)
      context.commit('setMsgSessionList', res.data)
    }
  }
}
